package cn.iocoder.yudao.module.cms.agreement.dal.mysql;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.cms.agreement.bo.AgreementIdentifyBO;
import cn.iocoder.yudao.module.cms.agreement.dal.dataobject.AgreementDO;
import cn.iocoder.yudao.module.cms.agreement.vo.AgreementPageReqVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 协议规则 Mapper
 *
 * @author 山野羡民
 */
@Mapper
public interface AgreementMapper extends CoreMapper<AgreementDO> {

    default PageResult<AgreementDO> selectPage(AgreementPageReqVO reqVO) {
        return selectPage(reqVO, new CoreLambdaQueryWrapper<AgreementDO>()
                .eqIfPresent(AgreementDO::getIdentify, reqVO.getIdentify())
                .betweenIfPresent(AgreementDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AgreementDO::getId)
                .orderByAsc(AgreementDO::getIdentify));
    }

    @Select("""
                    SELECT `value` as identify,`label` AS title
                    FROM `system_dict_data`
                    WHERE `dict_type`='cms_agreement_identify' AND `status`=0 AND `deleted`=0
                    ORDER BY `id` DESC
            """)
    List<AgreementIdentifyBO> selectAllIdentify();

}
